/*!
 * File   : includes/client.h
 * Author : Nandakiran Kirubanandan
 * 
 * This file contains the function declarations for the client side
 * access to the local tag server. All the tag applications (clients)
 * must communicate with the tag data structure (server) using these
 * functions.
 *
 */
#ifndef __client_h
#define __client_h
#include "nPatriciaTrie.h"
#include "linkedlist.h"
/*!
 * Function Name : clientlisttags
 * 	Returns a pointer to a linked list containing the tags of the
 * 	specified file.
 * Parameters	 : 
 * 		filename  : string
 * 			Name of the file whose tags is required.
 * Return Type   : *linkedlist
 *
 */
linkedlist* clientlisttags(char *filename);

/*!
 * Function Name : clientlisttags
 * 	Returns a pointer to a linked list containing the filenames which
 * 	are tagged with the specified tag.
 * Parameters	 : 
 * 		tag : string
 * 			The tag with which the files must be tagged.
 * Return Type   : *linkedlist
 *
 */
linkedlist* clientlistfiles(char *tag);

/*!
 * Function Name : clientaddtags
 * 	Adds a set of tags given in a linkedlist to the specified file.
 * Parameters	 : 
 * 		filename : string
 * 		tags	 : *linkedlist
 * Return Type   : void
 *
 */
void clientaddtags(char* filename, linkedlist* tags);
void autotag(char* folder);
void foldertag(char* folder, char* filename);
void autofoldertag(char* filename);

/*!
 * Function Name : clientremovetags
 * 	Removes a set of tags given in a linkedlist from the specified file.
 * Parameters	 : 
 * 		filename : string
 * 		tags	 : *linkedlist
 * Return Type   : void
 *
 */
void clientremovetags(char *filename, linkedlist *tags);

/*!
 * Function Name : clientcopyfile
 * 	Perform the require tag updates when a file is copied.
 * Parameters	 : 
 * 		src	 : string
 * 			The place from where the file is copied.
 * 		dest	 : string
 * 			The place to which the file is copied.
 * Return Type   : void
 *
 */
void clientcopyfile(char *src,char *dest);

/*!
 * Function Name : clientmovefile
 * 	Perform the require tag updates when a file is moved.
 * Parameters	 : 
 * 		src	 : string
 * 			The place from where the file is moved.
 * 		dest	 : string
 * 			The place to which the file is moved.
 * Return Type   : void
 *
 */
void clientmovefile(char *src,char *dest);

/*!
 * Function Name : clientremovefile
 * 	Perform the require tag updates when a file is deleted.
 * Parameters	 : 
 * 		src	 : string
 * 			The name of the file removed.
 * Return Type   : void
 *
 */
void clientremovefile(char *src);

/*!
 * Function Name : clientcopyfilerecurse
 * 	Perform the require tag updates when a directory is copied recursively.
 * Parameters	 : 
 * 		src	 : string
 * 			The place from where the directory is copied.
 * 		dest	 : string
 * 			The place to which the directory is copied.
 * Return Type   : void
 *
 */
void clientcopyfilerecurse(char *src,char *dest);

/*!
 * Function Name : clientmovefilerecurse
 * 	Perform the require tag updates when a directory is moved.
 * Parameters	 : 
 * 		src	 : string
 * 			The place from where the directory is moved.
 * 		dest	 : string
 * 			The place to which the directory is moved.
 * Return Type   : void
 *
 */
void clientmovefilerecurse(char *src,char *dest);

/*!
 * Function Name : clientremovefilerecurse
 * 	Perform the require tag updates when a directory is deleted.
 * Parameters	 : 
 * 		src	 : string
 * 			The name of the directory removed.
 * Return Type   : void
 *
 */
void clientremovefilerecurse(char *src);

/*!
 * Function Name : clientlistalltags
 * 	List all the tags in the tag structure.
 * Parameters	 : none 
 * Return Type   : *linkedlist
 * 			Pointer to a linked list containing the list of tags.
 *
 */
linkedlist* clientlistalltags();

/*!
 * Function Name : clientlistallfiles
 * 	List all the files in the tag structure.
 * Parameters	 : none 
 * Return Type   : *linkedlist
 * 			Pointer to a linked list containing the list of files.
 *
 */
linkedlist* clientlistallfiles();

/*!
 * Function Name : clientgetslashlist
 * 	List all the hierarchical directory tags.
 * Parameters	 : none 
 * Return Type   : *linkedlist
 * 			Pointer to a linked list containing the list of tags.
 *
 */
linkedlist* clientgetslashlist();

/*!
 * Function Name : clientsearch
 * 	Perfoms the search operation on the tag structure.
 * Parameters	 : 
 * 		which	 : string = macro FLATSEARCH or macro HIERARCHICAL
 * 			To indicate what type of search is to be performed.
 * 		tags	 : *linkedlist
 * 			The Actual query. A linkedlist of tags.
 * 		suggest  : *linkedlist
 * 			After the execution of the function, it will contain
 * 			a linked list of suggestions ( based on the type of 
 * 			search performed).
 * Return Type   : *linkedlist
 * 			Pointer to a linked list of files that satisfied the 
 * 			query. 
 *
 */
linkedlist* clientsearch(char *which,linkedlist* tags);

/*!
 * Function Name : clientgetsuggestions
 * 	Gets the possible suggestions to improve previous search.
 * Parameters	 : none
 * Return Type   : *linkedlist
 * 			Pointer to a linked list of suggestions
 *
 */
linkedlist* clientgetsuggestions();

/*!
 * Function Name : clientendserver
 * 	Terminate Server.
 * Parameters	 : none
 * Return Type   : none
 *
 */
void clientendserver();


linkedlist* clientrandomfile();
linkedlist* clientrandomtag();

long clientfilesinindex();
long clienttagsinindex();
void sigint_handler(int sig);
void inithandshake();
void closehandshake();
void clearsignals();
#endif
